package com.bjtu.literatureclient.service.authorindex;

import com.bjtu.literatureclient.dao.authorindex.AuthorIndexDao;
import com.bjtu.literatureclient.dao.user.UserIndexDao;
import com.bjtu.literatureclient.domain.authorindex.AuthorIndex;
import com.bjtu.literatureclient.domain.city.CityState;
import com.bjtu.literatureclient.domain.institution.CNInstitution;
import com.bjtu.literatureclient.domain.institution.ENInstitution;
import com.bjtu.literatureclient.domain.journal.JournalChinese;
import com.bjtu.literatureclient.domain.journal.JournalEnglish;
import com.bjtu.literatureclient.domain.publisher.CNPublisher;
import com.bjtu.literatureclient.domain.publisher.ENPublisher;
import com.bjtu.literatureclient.domain.user.UserIndexNoTable;
import com.bjtu.literatureclient.util.ChineseToPinyin;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service("AuthorIndexService")
public class AuthorIndexServiceImpl implements AuthorIndexService {
	@Autowired
	private AuthorIndexDao authorIndexDao;

	@Autowired
	private UserIndexDao userIndexDao;

	@Override
	public String getSurName(String surName) {
		// TODO Auto-generated method stub
		String surName1="";
		try {
				surName1= ChineseToPinyin.convertChineseToPinyin(surName, false,HanyuPinyinCaseType.LOWERCASE);
		} catch (BadHanyuPinyinOutputFormatCombination e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return surName1;
	}

	@Override
	public String getName(String name) {
		// TODO Auto-generated method stub
				String name1="";
				try {
						name1=ChineseToPinyin.convertChineseToPinyin(name, false,HanyuPinyinCaseType.LOWERCASE);
				} catch (BadHanyuPinyinOutputFormatCombination e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return name1;
	}

	@Override
	public Boolean addAuthorIndex(AuthorIndex authorIndex) {
		// TODO Auto-generated method stu		
		if(StringUtils.isEmpty(authorIndex))
			return false;
		System.out.println("IndexNo:"+authorIndex.getIndexNo()+"\tAuthorOrder:"+authorIndex.getAuthorOrder()
							+"\tLastName:"+authorIndex.getLastName()+"\tMiddleName:"+authorIndex.getMiddleName()
							+"\tFirstName:"+authorIndex.getFirstName()+"\tIndexCode:"+authorIndex.getIndexCode()+"\tEmail:"+authorIndex.getEmail());
		return authorIndexDao.addAuthorIndex(authorIndex);
	}

	@Override
	public Boolean addJournalTable2(JournalChinese journalChinese) {

		return authorIndexDao.addJournalTable2(journalChinese);
	}

	/*@Override
	public Boolean addPublisherTable2(CNPublisher cnPublisher) {
		// TODO Auto-generated method stub
		return authorIndexDao.addPublisherTable2(cnPublisher);
	}*/

	@Override
	public int getCityID(String Country, String Province, String City) {
		// TODO Auto-generated method stub
		   return authorIndexDao.getCityID(Country,Province,City);			
	}

	@Override
	public Boolean checkISSN(String Issn) {
		// TODO Auto-generated method stub
		return authorIndexDao.checkISSN(Issn);
	}

	@Override
	public Boolean addPublisherTable2(CNPublisher cnPublisher) {
		// TODO Auto-generated method stub
		return authorIndexDao.addPublisherTable2(cnPublisher);
	}

	@Override
	public Boolean addCityStateTable(CityState cityState) {
		// TODO Auto-generated method stub
		return authorIndexDao.addCityState(cityState);
	}

	@Override
	public String getStateName1(String stateName2) {
		// TODO Auto-generated method stub
		String stateName1="";//英文
		try {
			stateName1=ChineseToPinyin.convertChineseToPinyin(stateName2, false,HanyuPinyinCaseType.LOWERCASE);
		} catch (BadHanyuPinyinOutputFormatCombination e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return stateName1;
	}

	@Override
	public String getCity(String StateName2) {
		// TODO Auto-generated method stub
		return authorIndexDao.getCity(StateName2);
	}
	@Override
	public List getStateName2(String Region,String id) {
		// TODO Auto-generated method stub
		if(id.equals("2"))
		 return authorIndexDao.getStateName2(Region);
		else
			return authorIndexDao.getStateName1(Region);	
	}

	@Override
	public List<String> getCityName2(String StateName2) {
		// TODO Auto-generated method stub
		
			return authorIndexDao.getCityName2(StateName2);
	}
	@Override
	public List<String> getCityName1(String StateName1) {
		// TODO Auto-generated method stub
		
			return authorIndexDao.getCityName1(StateName1);
	}

	@Override
	public Boolean checkISSN1(String Issn) {
		// TODO Auto-generated method stub
		return authorIndexDao.checkISSN1(Issn);
	}

	@Override
	public Boolean addPublisherTable1(ENPublisher enPublisher) {
		// TODO Auto-generated method stub
		return authorIndexDao.addPublisherTable1(enPublisher);
	}

	@Override
	public int getCityID1(String Country, String Province, String City) {
		// TODO Auto-generated method stub
		return authorIndexDao.getCityID1(Country, Province, City);
	}

	@Override
	public Boolean addJournalTable1(JournalEnglish journalEnglish) {

		return authorIndexDao.addJournalTable1(journalEnglish);
	}

	@Override
	public String getChineseStateName2(String StateName1) {
		// TODO Auto-generated method stub

		return authorIndexDao.getChineseStateName2(StateName1);//由英文的名字得到中文的州或省的名字
	}

	@Override
	public Boolean addAuthorIndexs(List<AuthorIndex> authors) {
		for (AuthorIndex author : authors) {
			authorIndexDao.addAuthorIndex(author);
		}
		return true;
	}

	@Override
	public boolean addUSerIndex(UserIndexNoTable userIndexNoTable) {
		// TODO Auto-generated method stub
		return authorIndexDao.addUSerIndex(userIndexNoTable);
	}

	@Override
	public List<String> getPublisher() {
		// TODO Auto-generated method stub
		return authorIndexDao.getPublisher();
	}

	@Override
	public Boolean addInstitutionTable2(CNInstitution institution) {
		// TODO Auto-generated method stub
		return authorIndexDao.addInstitutionTable2(institution);
	}

	@Override
	public Boolean addInstitutionTable1(ENInstitution institution) {
		// TODO Auto-generated method stub
		return authorIndexDao.addInstitutionTable1(institution);
	}

	@Override
	public List<String> getPublisher1() {
		// TODO Auto-generated method stub
		return authorIndexDao.getPublisher1();
	}

	@Override
	public int getInstitutionID(String InstitutionName2) {
		// TODO Auto-generated method stub
		return authorIndexDao.getInstitutionID(InstitutionName2);
	}

	@Override
	public String getEnglishStateName1(String StateName2) {
		// TODO Auto-generated method stub
		return authorIndexDao.getEnglishStateName1(StateName2);
	}

	@Override
	public int getInstitutionID1(String InstitutionName) {
		// TODO Auto-generated method stub
		return authorIndexDao.getInstitutionID1(InstitutionName);
	}
}
